package com.xuecheng.content.api;

import com.xuecheng.content.model.dto.BindTeachplanMediaDto;
import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程计划编辑接口
 * Todo 编写查询接口根据课程id
 * @Author: chenheng
 * @Date: 2023/12/18 9:38
 */
@RestController
@Slf4j
@Api(value = "课程计划编辑接口",tags = "课程计划编辑接口")
public class TeachplanController {
    @Autowired
    TeachplanService teachplanService;
    //GET /teachplan/22/tree-nodes 根据课程id查询课程计划
    @ApiOperation("课程计划查询接口")
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId){
        List<TeachplanDto> teachplanTree = teachplanService.findTeachplanTree(courseId);
        return teachplanTree;
    }

    @ApiOperation("课程计划创建或修改")
    @PostMapping("/teachplan")
    public void saveTeachplan(@RequestBody SaveTeachplanDto dto){
        teachplanService.saveTeachplan(dto);
    }

    //content/teachplan/246
    @ApiOperation("课程计划删除")
    @DeleteMapping("/teachplan/{coursePlanId}")
    public void deleteTeachplan(@PathVariable Long coursePlanId){
        teachplanService.deleteTeachplan(coursePlanId);
    }

    //Request URL: http://localhost:8601/api/content/teachplan/movedown/43
    //Request Method: POST
    @ApiOperation("课程计划下移")
    @PostMapping("/teachplan/movedown/{coursePlanId}")
    public void movedownTeachplan(@PathVariable Long coursePlanId){
        teachplanService.movedownTeachplan(coursePlanId);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        teachplanService.associationMedia(bindTeachplanMediaDto);
    }
    @ApiOperation(value = "课程计划和媒资信息绑定删除")
    @DeleteMapping("/teachplan/association/media/{teachPlanId}/{mediaId}")
    public void deletAssociationMedia(@PathVariable Long teachPlanId,@PathVariable String mediaId){
        teachplanService.deletAssociationMedia(teachPlanId,mediaId);
    }
}
